//
//  PostBrowseCell.m
//  sensen_ios
//
//  Created by pro on 16/3/1.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "PostBrowseCell.h"

#import "PostImgsView.h" // 图片视图

@interface PostBrowseCell ()
{
    UIImageView *_iconImgView; // 头像
    UILabel *_nickLabel; // 昵称
    UILabel *_contentLabel; // 帖子内容
    PostImgsView *_postImgsView; // 图片
    
    UIImageView *_timeImgView; // 时间图片
    UILabel *_postTimeLabel; // 发表时间 //论坛_进入论坛_时间
    
    UIImageView *_favourImgView; // 点赞图片
    UIImageView *_commentImgView; // 回复图片
    UILabel *_favourLabel; // 点赞数量
    UILabel *_commentLabel; // 回复数量
    UIImageView *_disImageView;

}

@end

@implementation PostBrowseCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        for(UIView *view in self.contentView.subviews) {
            [view removeFromSuperview];
        }
        [self _initViews];
    }
    return self;
}

#pragma mark -- 创建视图 --
- (void)_initViews {
   
    // 头像
    _iconImgView = [[UIImageView alloc] init];
    _iconImgView.image = [UIImage imageNamed:@"person_message_disabled"];
    _iconImgView.clipsToBounds = YES;
    [self.contentView addSubview:_iconImgView];
    
    // 昵称
    _nickLabel = [[UILabel alloc] init];
    _nickLabel.font = B_FONT(15);
    _nickLabel.text = @"发帖人昵称";
    _nickLabel.textColor = rgba(12, 91, 158, 1);
    _nickLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_nickLabel];
    
    //加精标志
    _disImageView = [[UIImageView alloc] init];
    _disImageView.image = [UIImage imageNamed:@"论坛首页-导航_精华帖1"];
    [self.contentView addSubview:_disImageView];
    _disImageView.hidden = YES;
    
    // 内容
    _contentLabel = [[UILabel alloc] init];
    _contentLabel.font = FONT(16);
    _contentLabel.numberOfLines = 0;
    _contentLabel.text = @"发帖发帖内容发帖内容发帖内容发帖内容发帖内容发帖内容发帖内容";
    _contentLabel.textColor = [UIColor darkGrayColor];
    _contentLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_contentLabel];
    
    // 图片视图
    _postImgsView = [[PostImgsView alloc] init];
    [self.contentView addSubview:_postImgsView];
    _postImgsView.left = 0;
    _postImgsView.top = _contentLabel.bottom + 5;
    
    // 发表时间
    _timeImgView = [[UIImageView alloc] init];
    _timeImgView.image = [UIImage imageNamed:@"论坛_进入论坛_时间"];
    [self.contentView addSubview:_timeImgView];
    _postTimeLabel = [[UILabel alloc] init];
    _postTimeLabel.font = FONT(13);
    _postTimeLabel.text = @"5天前";
    _postTimeLabel.textColor = [UIColor darkGrayColor];
    _postTimeLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_postTimeLabel];
    
    // 回复
    _commentImgView = [[UIImageView alloc] init];
    _commentImgView.image = [UIImage imageNamed:@"论坛_进入论坛_评论"];
    [self.contentView addSubview:_commentImgView];
    _commentLabel = [[UILabel alloc] init];
    _commentLabel.font = FONT(13);
    _commentLabel.text = @"6666";
    _commentLabel.textColor = [UIColor colorWithRGBHex:0xaaaaaa];
    _commentLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_commentLabel];
    
    // 点赞
    _favourImgView = [[UIImageView alloc] init];
    _favourImgView.image = [UIImage imageNamed:@"论坛_进入论坛_赞"];
    [self.contentView addSubview:_favourImgView];
    _favourLabel = [[UILabel alloc] init];
    _favourLabel.font = FONT(13);
    _favourLabel.text = @"6666";
    _favourLabel.textColor = [UIColor colorWithRGBHex:0xaaaaaa];
    _favourLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_favourLabel];
    
}


#pragma mark - 重写set
- (void)setLayout:(PostCellFrameLayout *)layout {
    
    if (_layout != layout) {
        _layout = layout;
    }
//    _layout = layout;
    
    // 设置属性和布局
    [self _setAttributeAndLayout];
    
}

// 设置属性和布局
- (void)_setAttributeAndLayout {
    
    PostModel *model = _layout.model;
    
    // 设置头像
    _iconImgView.frame = _layout.iconRect;
    NSURL * url;
    if (model.authorImage != nil) {
        url = [[NSURL alloc]initWithString:model.authorImage];
    }
    [_iconImgView setImageWithURL: url placeholderImage:[UIImage imageNamed:@"defaultImage"]];
    // 设置头像圆角
    _iconImgView.layer.cornerRadius = _layout.iconRect.size.width / 2;
    
    // 设置昵称
    _nickLabel.frame = _layout.nickRect;
    _nickLabel.text = model.nickname;
    
    _disImageView.frame = _layout.disImageViewRect;
    if ([model.digest intValue] == 1) {
        _disImageView.hidden = NO;
    }else{
        _disImageView.hidden = YES;
    }
    
    // 设置内容视图
    _contentLabel.frame = _layout.contentRect;
    _contentLabel.text = model.postTitle;
    
    // 图片
    _postImgsView.imgAry = model.imgAry;
    _postImgsView.frame = _layout.imgRect;
    
    // 设置时间
    _timeImgView.frame = _layout.timeImgRect;
    _postTimeLabel.frame = _layout.timeRect;
    _postTimeLabel.text = model.dateline_show;
    // 设置评论
    _commentImgView.frame = _layout.commentImgRect;
    _commentLabel.frame = _layout.commentRect;
    _commentLabel.text = model.replies;
    
    // 设置点赞
    _favourImgView.frame = _layout.favourImgRect;
    _favourLabel.frame = _layout.favourRect;
    _favourLabel.text = model.likes;
    
}
     
#pragma mark - 点击事件
@end
